﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Utility
{
    public class Logger
    {
        static readonly string LogPath = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "My Service", "MyService.log");
        public static void Write(string message)
        {
            if (!Directory.Exists(Path.GetDirectoryName(LogPath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(LogPath));
            }

            string logMsgFormat = "{0} : {1}";
            using (StreamWriter sw = new StreamWriter(LogPath, true))
            {
                sw.WriteLine(logMsgFormat, DateTime.Now, message);
            }
        }
    }
}
